package com.yunsc.admin.controller.product;

import com.yunsc.common.utils.Result;
import com.yunsc.common.utils.SecurityUtil;
import com.yunsc.common.validator.ValidationGroups;
import com.yunsc.product.dto.GoodsCategoryDTO;
import com.yunsc.product.service.YunscGoodsCategoryService;
import com.yunsc.product.vo.GoodsCategoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-04-14 0:33
 */
@Api(value = "商品信息管理", tags = "商品分类接口")
@RestController
@RequestMapping("category")
public class GoodsCategoryController {

    @Resource
    private YunscGoodsCategoryService goodsCategoryService;

    /**
     * 列表
     */
    @ApiOperation("查询商品分类接口")
    @GetMapping("/list")
    public Result<Map<String, Object>> list() {
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        List<GoodsCategoryVO> list = goodsCategoryService.queryGoodsCategory(currentStoreId);
        return Result.resultList(list);
    }




    @ApiOperation("添加商品分类")
    @PostMapping("/add")
    public Result add(@RequestBody GoodsCategoryDTO body){
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        goodsCategoryService.addGoodsCategory(body, currentStoreId);
        return Result.ok();
    }

    @ApiOperation("修改商品分类")
    @PostMapping("/edit")
    public Result edit(@RequestBody @Validated({ValidationGroups.Update.class}) GoodsCategoryDTO body){
        goodsCategoryService.editGoodsCategory(body);
        return Result.ok();
    }
    @ApiOperation("删除商品分类")
    @PostMapping("/delete")
    public Result delete(@RequestBody @Validated({ValidationGroups.Delete.class}) GoodsCategoryDTO body){
        goodsCategoryService.deleteGoodsCategoryById(body.getCategoryId());
        return Result.ok();
    }

    @ApiOperation("分类显示/隐藏")
    @PostMapping("/state")
    public Result state(@RequestBody @Validated({ValidationGroups.Update.class}) GoodsCategoryDTO body) {
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        goodsCategoryService.updateGoodsCategoryState(body, currentStoreId);
        return Result.ok();
    }

}
